package 力扣.字符串;

import java.util.Arrays;
import java.util.Scanner;

public class 字符串校对 {
    /**
     * 1. 三个同样的字母连在一起，一定是拼写错误，去掉一个的就好啦：比如 helllo -> hello
     * 2. 两对一样的字母（AABB型）连在一起，一定是拼写错误，去掉第二对的一个字母就好啦：比如 helloo -> hello
     * 3. 上面的规则优先“从左到右”匹配，即如果是AABBCC，虽然AABB和BBCC都是错误拼写，应该优先考虑修复AABB，结果为AABCC
     */
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final  int N = sc.nextInt();
        for (int i = 0; i < N; i++) {
            String s = sc.next();
            char[] chars = s.toCharArray();
            int left= 0;
            for (int j = 0; j < chars.length; j++) {
                chars[left++] = chars[j];
                if (left >= 3 && chars[left -1] == chars[left - 2] && chars[left - 2] == chars[left -3]){
                    left--;
                }
                if (left >= 4 && chars[left - 1] == chars[left - 2] && chars[left - 3] == chars[left -4]){
                    left--;
                }
            }
            System.out.println(new String(chars).substring(0,left));
        }
    }
    public static void main2(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i =0;i < n;i++){
            String s1 = sc.next();
            char[] s = s1.toCharArray();
            int k = 0;
            for(int j =0;j<s.length;j++){
                s[k++] = s[j];
                if(k>=3 && s[k-3]==s[k-2] &&s[k-2] == s[k-1]) k--;
                if(k>=4 && s[k-4]==s[k-3] &&s[k-2] == s[k-1]) k--;
            }

            System.out.println(new String(s).substring(0,k));
        }
    }




}
